package cn.cloud9;

public class Case7FindPythagoreanNumber {

    /**
     * http://c.biancheng.net/view/506.html
     * 求100以内的所有勾股数。
     * 所谓勾股数，是指能够构成直角三角形三条边的三个正整数（a，b，c）。
     * @param args
     */
    public static void main(String[] args) {
        solution2();
    }

    private static void solution1() {
        final int RANGE = 100;
        for (int a = 1; a < RANGE; a++) {
            for (int b = a + 1; b < RANGE; b++) {
                for (int c = b + 1; c < RANGE; c++) {
                    double powA = Math.pow(a, 2);
                    double powB = Math.pow(b, 2);
                    double powC = Math.pow(c, 2);
                    if (powA + powB == powC) System.out.printf( "a:%d b:%d c:%d\n", a, b, c );
                }
            }
        }
    }

    private static void solution2() {
        final int RANGE = 100;
        int a, b, c, count = 0;

        for (a = 1; a < RANGE; a++) {
            for (b = a + 1; b < RANGE; b++) {
                double v = Math.pow(a, 2) + Math.pow(b, 2);
                c = (int) Math.sqrt(v);

                if (
                    RANGE >= c
                    && a + b > c
                    && a + c > b
                    && b + c > a
                    && Math.pow(c, 2) == v) {
                    ++ count;
                    System.out.printf( "a:%d b:%d c:%d count:%d\n", a, b, c, count);
                }
            }
        }
    }
}
